package com.topscomm.main.config;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class CbbThreadPoolUtil {
    // 获取服务器的cpu个数
    private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();// 获取cpu个数
    private static final int COUR_SIZE = CPU_COUNT;
    private static final int MAX_COUR_SIZE = CPU_COUNT * 2;

    @Bean(value = "cbbThreadPool")
    ExecutorService createThreadPool(){
        ExecutorService threadPool = new ThreadPoolExecutor(COUR_SIZE, MAX_COUR_SIZE, 5, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(1000),
            new CbbThreadFactory("cbb-pm-thread-work"), new ThreadPoolExecutor.DiscardPolicy());
        return threadPool;
    }
}
